package com.tiany.tiange_study;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.tiany.tiange_study.GridActivity.GridViewActivity;
import com.tiany.tiange_study.ListActivity.ListViewActivity;

public class MainActivity extends AppCompatActivity {

    private Button mBtnEditText;
    private Button mBtnRadioButton;
    private Button mBtnCheckBox;
    private Button mBtnImageView;
    private Button mBtnListView;
    private Button mBtnGridView;
    private Button mBtnScrollView;
    private Button mBtnWebView;
    private Button mBtnToastView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //编辑框
        mBtnEditText = findViewById(R.id.btn_edittext);
        //单选按钮
        mBtnRadioButton = findViewById(R.id.btn_radiobtn);
        //复选框
        mBtnCheckBox = findViewById(R.id.btn_checkbox);
        //图片框
        mBtnImageView = findViewById(R.id.btn_imgview);
        //列表框
        mBtnListView = findViewById(R.id.btn_listview);
        //网格视图
        mBtnGridView= findViewById(R.id.btn_gridview);
        //滚动视图
        mBtnScrollView= findViewById(R.id.btn_scrollview);
        //webview
        mBtnWebView= findViewById(R.id.btn_webview);
        //ToastView
        mBtnToastView=findViewById(R.id.btn_toastview);
        //调用
        setListener();
    }

    private void setListener() {
        OnClick onClick = new OnClick();
        mBtnEditText.setOnClickListener(onClick);
        mBtnRadioButton.setOnClickListener(onClick);
        mBtnCheckBox.setOnClickListener(onClick);
        mBtnImageView.setOnClickListener(onClick);
        mBtnListView.setOnClickListener(onClick);
        mBtnGridView.setOnClickListener(onClick);
        mBtnScrollView.setOnClickListener(onClick);
        mBtnWebView.setOnClickListener(onClick);
        mBtnToastView.setOnClickListener(onClick);
    }

    private class OnClick implements View.OnClickListener {

        @SuppressLint("NonConstantResourceId")
        @Override
        public void onClick(View v) {
            Intent intent = null;
            switch (v.getId()) {
                case R.id.btn_edittext:
                    intent = new Intent(MainActivity.this, EditTextActivity.class);
                    break;
                case R.id.btn_radiobtn:
                    intent = new Intent(MainActivity.this, RadioButtonActivity.class);
                    break;
                case R.id.btn_checkbox:
                    intent = new Intent(MainActivity.this, CheckBoxActivity.class);
                    break;
                case R.id.btn_imgview:
                    intent = new Intent(MainActivity.this, ImageViewActivity.class);
                    break;
                case R.id.btn_listview:
                    intent = new Intent(MainActivity.this, ListViewActivity.class);
                    break;
                case R.id.btn_gridview:
                    intent=new Intent(MainActivity.this, GridViewActivity.class);
                    break;
                case R.id.btn_scrollview:
                    intent=new Intent(MainActivity.this, ScrollViewActivity.class);
                    break;
                case R.id.btn_webview:
                    intent=new Intent(MainActivity.this,WebViewActivity.class);
                    break;
                case R.id.btn_toastview:
                    intent=new Intent(MainActivity.this,ToastActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }
}